package com.sky.controller.admin;

import com.sky.constant.JwtClaimsConstant;
import com.sky.dto.EmployeeDTO;
import com.sky.dto.EmployeeLoginDTO;
import com.sky.dto.EmployeePageQueryDTO;
import com.sky.entity.Employee;
import com.sky.properties.JwtProperties;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.EmployeeService;
import com.sky.utils.JwtUtil;
import com.sky.vo.EmployeeLoginVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 员工管理
 */
@RestController
@RequestMapping("/admin/employee")
@Slf4j
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @PostMapping("/login")
    @ApiOperation("登录")
    public Result<EmployeeLoginVO> login(
            @RequestBody EmployeeLoginDTO employeeLoginDTO) {

        log.info("员工登录：{}", employeeLoginDTO);

        return Result.success(employeeService.login(employeeLoginDTO));
    }

    /**
     * 退出
     *
     * @return
     */
    @PostMapping("/logout")
    @ApiOperation("退出")
    public Result<String> logout() {
        return Result.success();
    }

    /**
     *  员工分页查询
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("员工分页查询")
    public Result<PageResult> page(EmployeePageQueryDTO employeePageQueryDTO){
        log.info("控制层：员工分页操作开始，获得请求数据：{}" + employeePageQueryDTO);
        return employeeService.page(employeePageQueryDTO) ;
    }

    /**
     * 新增员工
     * @return
     */
    @PostMapping
    @ApiOperation("新增员工")
    public Result addEmp(@RequestBody EmployeeDTO employeeDTO){
        log.info("emp控制层：新增员工操作开始，获得请求数据：{}" + employeeDTO);
        return employeeService.addEmp(employeeDTO);
    }


    /**
     *  改变员工状态
     * @return
     */
    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用员工账号")
    public Result changeEmpStatus( @PathVariable Integer status , Long id){
        return employeeService.changeEmpStatus(status, id);
    }


    /**
     * 根据ID查询，回显员工信息
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询员工信息")
    public Result<Employee> getByID(@PathVariable Long id){
        return employeeService.getByID(id);
    }

    /**
     * 修改员工信息
     * @return
     */
    @PutMapping
    @ApiOperation("编辑员工信息")
    public Result updateEmp(@RequestBody EmployeeDTO employeeDTO ){
        return employeeService.updateEmp(employeeDTO);
    }

}
